package com.ruochen.order;

import com.ruochen.feign.clients.UserClient;
import com.ruochen.feign.config.DefaultFeignConfiguration;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@MapperScan("com.ruochen.order.mapper")
@SpringBootApplication
// 启动扫描不到feign-api client 解决方案
// 一：指定FeignClient所在包
// @EnableFeignClients(defaultConfiguration = DefaultFeignConfiguration.class, basePackages = "com.ruochen.feign.clients")
// 二：指定FeignClient字节码
@EnableFeignClients(defaultConfiguration = DefaultFeignConfiguration.class, clients = {UserClient.class})
public class OrderApplication {

    public static void main(String[] args) {
        SpringApplication.run(OrderApplication.class, args);
    }

    /**
     * 创建RestTemplate 并注入Spring容器
     *
     * @return RestTemplate 对象
     */
    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    /**
     * 更改LB方案1，全局生效(不管调用哪个service都是按照以下规则)
     * 更改 RibbonLB 规则
     *
     * @return LB 规则
     */
    /*
    @Bean
    public IRule randomRule() {
        return new RandomRule();
    }
    */
}